$(function() {
    $.validator.setDefaults({
        submitHandler: function() {
            //alert('提交!');

            var jsonData = $('#ajaxForm').serialize();
            $.ajax({
                type: "POST",
                url: "/admin/setup/save",
                data: jsonData,
                success: function (data) {
                    toastr.success('配置成功!')
                    window.location.reload();
                },
                error:function (data) {
                    toastr.error('请检查后再提交.', '保存失败!', {
                        closeButton: true,
                        progressBar: true
                    });
                    //window.location.reload();

                }

            });
        }
    });
    $('#ajaxForm').validate({
        rules: {
            title: 'required'
        },
        messages: {
            title: 'Please enter your firstname'

        },
        errorElement: 'em',
        errorPlacement: function(error, element) {
            // Add the `help-block` class to the error element
            error.addClass('form-control-feedback');
            if (element.prop('type') === 'checkbox') {
                error.insertAfter(element.parent('label'));
            } else {
                error.insertAfter(element);
            }
        },
        highlight: function(element, errorClass, validClass) {
            $(element).addClass('form-control-danger').removeClass('form-control-success');
            $(element).parents('.form-group').addClass('has-danger').removeClass('has-success');
        },
        unhighlight: function(element, errorClass, validClass) {
            $(element).addClass('form-control-success').removeClass('form-control-danger');
            $(element).parents('.form-group').addClass('has-success').removeClass('has-danger');
        }
    });
});
